from wcs.libs.players import players

class CompatabilityManager(object):
    """
    This object is here to create an object orientated method to manage the
    backwards compatability of this mod so that older python races will work.
    Depricated methods should exist in here, and a global link should give
    referenece to class methods here.
    """
    def __init__(self):
        """
        Executed when this object is created. Ensure that we create all global
        aspects of the backwards compatibility functions.
        """
        globalDict = globals()
        globalDict["GetLevel"] = self.getLevel
        globalDict["Command"]  = self.getCommandInstance

    def getLevel(self, userid, raceName, skillName):
        """
        Returns the level of a skill for a given race and user.

        @param integer userid The ID of the user
        @param string raceName The name of the race to get the skill level
        @param string skillname The name of the skill
        @return integer The level of the skill
        """
        if userid in players:
            player = players[userid]
            if raceName == player.currentRace:
                race = player[raceName]
                skill = race[skillName]
                return skill.level
        return 0

    def getCommandInstance(self, userid):
        """
        Return the command instance for a player object.

        @param integer userid The ID of a user
        @return PlayerObject The command object of a user.
        """
        return players[userid].command
    
CompatabilityManager() # Instantate the object creating the backwards compat